package com.block.account.service.impl;

import com.block.account.model.dto.ChangeAmountDTO;
import com.block.db.entity.AccountMerchantInfo;
import com.block.db.entity.AccountMerchantInfoHis;
import com.block.db.entity.MerchantBaseInfo;
import com.block.db.mapper.AccountMerchantInfoHisMapper;
import com.block.account.service.IAccountMerchantInfoHisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.block.db.mapper.MerchantBaseInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * <p>
 * 商户账户流水 服务实现类
 * </p>
 *
 * @author
 * @since 2023-08-26
 */
@Service
public class AccountMerchantInfoHisServiceImpl extends ServiceImpl<AccountMerchantInfoHisMapper, AccountMerchantInfoHis> implements IAccountMerchantInfoHisService {
    @Resource
    MerchantBaseInfoMapper merchantBaseInfoMapper;

    @Override
    public boolean saveAccountHis(BigDecimal currentAmount, AccountMerchantInfo accountMerchantInfo, ChangeAmountDTO changeAmountDTO) {

        MerchantBaseInfo baseInfo = merchantBaseInfoMapper.selectById(accountMerchantInfo.getInfoId());

        AccountMerchantInfoHis merchantInfoHis = new AccountMerchantInfoHis();
        merchantInfoHis.setOwnerId(baseInfo.getOwnerId());
        merchantInfoHis.setOwnerName(baseInfo.getOwnerName());
        merchantInfoHis.setAccountId(accountMerchantInfo.getInfoId());
        merchantInfoHis.setAccountName(changeAmountDTO.getAccountName());
        merchantInfoHis.setDateInfo(LocalDate.now().toString());
        merchantInfoHis.setBillDateInfo(changeAmountDTO.getBillDateInfo());
        merchantInfoHis.setActionType(changeAmountDTO.getActionTypeEnum().getValue());
        merchantInfoHis.setCurrentAmount(currentAmount);
        merchantInfoHis.setOriginAmount(accountMerchantInfo.getTotalAmount());
        merchantInfoHis.setChangeAmount(changeAmountDTO.getChangeAmount());
        merchantInfoHis.setDataInfo(changeAmountDTO.getDataInfo());
        merchantInfoHis.setRemarkInfo(changeAmountDTO.getRemarkInfo());
        merchantInfoHis.setOpertorId(changeAmountDTO.getOperatorId());
        merchantInfoHis.setOpertorName(changeAmountDTO.getOperatorName());

        boolean save = this.save(merchantInfoHis);

        return save;
    }
}
